Parent:
DateTime extension methods provide utility functions for working with dates and times, particularly for trading calendars, option expiration dates, date formatting, and time-based strategy logic. Call these methods directly on a DateTime instance using standard extension method syntax.
Returns a DateTime representing the first day of the month containing dt.
Returns a DateTime containing the same year, month, day, hour, and minute as dt, with seconds and milliseconds set to zero. The DateTime Kind is preserved.
Returns the time portion of dt as a 24-hour HHmm integer. For example, 4:00 PM returns 1600.
Returns the time portion of dt as a 24-hour HHmm integer. Seconds are ignored. Examples
- 9:35 AM => 935
- 12:00 PM => 1200
- 3:50 PM => 1550
Returns true if dt represents, or is very close to, DateTime.MaxValue. The method considers any DateTime whose year is 9999 to be a maximum value.
Returns true if dt represents, or is very close to, DateTime.MinValue. The method considers any DateTime whose year is 2 or earlier to be a minimum value.
Returns the zero-based calendar quarter containing dt. Possible values are:
- 0 = January through March
- 1 = April through June
- 2 = July through September
- 3 = October through December
Returns a DateTime containing the same year, month, day, hour, and minute as dt, with the seconds set to zero.
Returns the zero-based half-year containing dt. Returns 0 for January through June and 1 for July through December.
Returns the number of calendar days between fromDate and toDate. The result is positive when toDate is later, zero when the dates are the same, and negative when toDate is earlier. When using the string overload, dates must be in yyyyMMdd format, for example:
int days = "20260801".CalendarDaysBetweenDates("20260826");
When using the integer overload, dates must also be expressed in yyyyMMdd format:
int days = 20260801.CalendarDaysBetweenDates(20260826);
Returns dt formatted as a JavaScript-oriented date/time string using the form yyyy-MM-ddThh:mm:ssZ.
Converts dateTime to UTC and returns an ISO 8601-style date/time string.
Returns C# source code representing the date portion of dt as a DateTime constructor. For example, a DateTime representing August 26, 2026 returns:
new DateTime(2026,8,26)
Returns dt using the current culture's short date format followed by a 24-hour time. By default, the time contains hours and minutes. Pass true for useSeconds to include seconds.
Returns a short date and time string if dt contains a non-zero time component. If the time is midnight, only the short date is returned.
Determines whether date is a monthly option expiration date. The parameterless version identifies the third Friday of the month and also accounts for U.S. stock market holidays that move expiration from Friday to Thursday. The BarHistory version uses the market calendar associated with bars to determine the applicable expiration date.
Returns the next option expiration date on or after date. By default, the method returns the next monthly expiration, normally the third Friday of the month. If the expiration Friday is a market holiday, the preceding trading day is returned. Pass true for useWeeklies to determine the next weekly expiration instead.
Returns the nth occurrence of the specified dow DayOfWeek within the month containing dt. For example, the following returns the third Friday of the month:
DateTime thirdFriday = dt.NthDayOfWeek(3, DayOfWeek.Friday);
Returns the options week of the month, from 1 through 5. Options weeks are defined as Saturday through Friday, and a week belongs to the month containing its Friday.
Returns the options week of the year, from 1 through 53. Options weeks are defined as Saturday through Friday and belong to the year containing the week's Friday.
Returns the date of the third Friday in the month containing tempDate.
Returns the next trading date after dt, based on the market associated with bars, or the specified mkt. Market trading days and holidays are taken into account. If dt contains a time component, it is preserved in the returned value.
Returns true if the market associated with bars trades on the date represented by dt. Holidays and the market's configured trading days of the week are taken into account. The time portion of dt is ignored.
Returns true if the date represented by dt is contained in the holiday dates of the market associated with bars.
Returns true if dt represents the last trading day of a calendar month for the market associated with bars.
Returns true if dt represents the last trading day of a calendar week for the market associated with bars.
Returns true if the market associated with bars trades on the date represented by dt. Holidays and the market's configured trading days of the week are taken into account. The time portion of dt is ignored.
Returns true if dt falls on a Saturday or Sunday.
Returns the trading day immediately preceding dt, based on the specified md MarketDetails instance. If dt contains a time component, it is preserved.
Returns the trading-day number within the month for dt, based on the market associated with bars.
Returns the trading-hour number for dt based on the market hours associated with bars. Returns zero when dt is outside regular market hours.
Returns the number of milliseconds between January 1, 1970 and dt.
Converts a Unix timestamp to a UTC DateTime. By default, unixDate is interpreted as seconds since the Unix epoch. Pass true for inputInMS if the value is already expressed in milliseconds.
Returns true if dt falls in the first week of the class's alternating two-week cycle. The cycle is anchored to January 1, 1900. The supplied date is assumed to represent the first trading day of a week, allowing a Tuesday following a Monday holiday to be treated as belonging to that Monday's week.
Returns the calendar week number of dte, from 1 through 52 or 53. Week 1 is defined as the first full Sunday-through-Saturday week in January. Consequently, dates at the beginning of January can belong to the final week of the preceding year's week sequence.